#!/usr/bin/env bash
#20230706
base_path=/app/oem/ai
if [ -e "/sys/class/gpio/gpio304" ];then
   echo "GPIO 304 exist"
else 
   echo "GPIO 304 does not exist,make it"
   echo 304 > /sys/class/gpio/export
   sleep 1
   echo out > /sys/class/gpio/gpio304/direction
   sleep 1
   echo in > /sys/class/gpio/gpio304/direction
fi
if [ -e "/sys/class/gpio/gpio342" ];then
  echo "GPIO 342 exist"
else 
  echo "GPIO 342 does not exist,make it"
  echo 342 > /sys/class/gpio/export
  sleep 1
  echo in > /sys/class/gpio/gpio342/direction
  sleep 1
  echo out > /sys/class/gpio/gpio342/direction
  sleep 1
  echo 1 > /sys/class/gpio/gpio342/value
fi

echo 410 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio410/direction
echo 0 > /sys/class/gpio/gpio410/value

service rsyslog stop

sleep 1
rs-enumerate-devices -c > /app/calib/D450.yaml
sleep 1
rm -rf /home/nvidia/.ros/log/*
rm -rf /root/.ros/log/*
rm -rf /var/log/*
rm -rf ${base_path}/positec/robot_logs/SLAM/*
${base_path}/positec/robot_service/syslog.sh &

rm -rf ${base_path}/positec/robot_logs/traffic.log
${base_path}/positec/robot_service/traffic 192.168.10.150 1.2 > ${base_path}/positec/robot_logs/traffic.log &
jetson_clocks
${base_path}/positec/robot/src/d450-yaml-parse/build/ParseSensorConfig &
sleep 1
${base_path}/positec/robot_service/clear_bufcache.sh &
echo 255 > /sys/devices/pwm-fan/target_pwm
echo 0 > /proc/sys/kernel/printk
bash -c "source /opt/ros/melodic/setup.bash && source ${base_path}/positec/robot/devel/setup.bash && roslaunch start_robot start_robot.launch;exec bash"
